package com.example.ivos.dictoption.controller;

import com.example.ivos.base.response.JsonResult;
import com.example.ivos.dict.mapper.DictMapper;
import com.example.ivos.dict.pojo.dto.DictQuery;
import com.example.ivos.dict.pojo.entity.Dict;
import com.example.ivos.dict.pojo.vo.DictVO;
import com.example.ivos.dictoption.pojo.dto.DictOptionQuery;
import com.example.ivos.dictoption.pojo.dto.DictOptionSaveParam;
import com.example.ivos.dictoption.pojo.vo.DictOptionVO;
import com.example.ivos.dictoption.service.DictOptionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/dictOption/")
public class DictOptionController {
    @Autowired
    private DictOptionService dictOptionService;

    @GetMapping("select")
    public JsonResult selectDictOption(DictOptionQuery dictOptionQuery) {
        log.debug("查询字典项参数:{}", dictOptionQuery);
        List<DictOptionVO> list = dictOptionService.selectDictOption(dictOptionQuery);
        return JsonResult.ok(list);
    }
    @PostMapping("save")
    public JsonResult save(DictOptionSaveParam dictOptionSaveParam) {
        log.debug("保存字典项信息:dictOptionSaveParam={}",dictOptionSaveParam);
        dictOptionService.save(dictOptionSaveParam);
        return JsonResult.ok();

    }
    @PostMapping("delete/{id}")
    public JsonResult delete(@PathVariable Long id) {
        dictOptionService.delete(id);
        return JsonResult.ok();
    }
    //定义一个根据字典code查字典项的方法
    @GetMapping("select1/{code}")
    public JsonResult selectDictOptionByCode(@PathVariable String code) {
        log.debug("查询字典项参数:{}", code);
       List<DictOptionVO> list=dictOptionService.selectDictOptionByCode(code);
        return JsonResult.ok(list);
    }
}